package net.sea.setup.ui.wizard.impl;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import net.sea.commons.constants.AppConstants;
import net.sea.setup.config.custom.CustomConfig;
import net.sea.setup.ui.wizard.AbstractWizardPage;

/**
 * 安装摘要信息
 * 
 * @author 华成伍
 *
 */
@SuppressWarnings("serial")
public class SummaryPage extends AbstractWizardPage {
	private JTextPane summTextPane = new JTextPane();

	public SummaryPage() {
		setBorder("\u5B89\u88C5\u4FE1\u606F");
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 10, 440, 10 };
		gridBagLayout.rowHeights = new int[] { 10, 278, 10 };
		gridBagLayout.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		setLayout(gridBagLayout);

		JScrollPane summaryScrollPane = new JScrollPane();
		GridBagConstraints gbc_summaryScrollPane = new GridBagConstraints();
		gbc_summaryScrollPane.insets = new Insets(0, 0, 5, 5);
		gbc_summaryScrollPane.fill = GridBagConstraints.BOTH;
		gbc_summaryScrollPane.gridx = 1;
		gbc_summaryScrollPane.gridy = 1;
		add(summaryScrollPane, gbc_summaryScrollPane);

		summaryScrollPane.setViewportView(summTextPane);

	}

	/**
	 * 初始化摘要内容
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void process() {
		super.done();
		Map<String, CustomConfig> customMap = (Map<String, CustomConfig>) contextInst
				.getAttribute(AppConstants.CUSTOM_CONFIG_KEY);
		Set<String> keySet = customMap.keySet();
		StringBuffer content = new StringBuffer();
		content.append("平台安装信息如下：\n\n");
		for (String key : keySet) {
			content.append(customMap.get(key).toString());
		}
		summTextPane.setText(content.toString());
	}

	@Override
	public void done() {
		super.done();
		logger.info("用户设置的安装信息如下：\n" + summTextPane.getText());
	}

	@Override
	public PageResult validateInput() {
		return new PageResult(true);
	}

	@Override
	protected List<CustomConfig> createCustomConfig() {
		return null;
	}
}
